import React, { Component } from 'react';
import { Toast } from 'react-weui';

export default class ToastUi extends Component {

    state = {
        showSuccessToast: false
    };

    componentDidMount(){
        console.log(this.props.ret);
        if(this.props.ret == 0){
            this.setState({showSuccessToast: true});
            this.state.toastTimer = setTimeout(()=> {
                this.setState({showSuccessToast: false});
            }, 2000);
        }else if(this.props.ret == -1){
            this.setState({showErrorToast: true});
            this.state.toastTimer = setTimeout(()=> {
                this.setState({showErrorToast: false});
            }, 2000);
        }
        
    }

    render() {
        return (
            <div>
                <Toast icon="success-no-circle" show={this.state.showSuccessToast}>成功</Toast>
                <Toast icon="success-no-circle" show={this.state.showErrorToast}>失败</Toast>
            </div>
        )
    }
}
